package com.example.helloandroid;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.StrictMode;

public class SystemUtil {
    //private static final String TAG = SystemUtil.class.getSimpleName();

    public static boolean enableComponent(Context ctx, String cls) {
        try {
            PackageManager pm = ctx.getPackageManager();
            ComponentName name = new ComponentName(ctx, cls);
            pm.setComponentEnabledSetting(name,PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                       PackageManager.DONT_KILL_APP);
            return true;
        } catch (Exception e) {}
        return false;
    }

    public static boolean disableComponent(Context ctx, String cls) {
        try {
            PackageManager pm = ctx.getPackageManager();
            ComponentName name = new ComponentName(ctx, cls);
            pm.setComponentEnabledSetting(name,PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                       PackageManager.DONT_KILL_APP);              
            return true;
        } catch (Exception e) {}
        return false;
    }

    public static boolean isComponentEnabled(Context ctx, String cls) {
        PackageManager pm = ctx.getPackageManager();
        ComponentName name = new ComponentName(ctx, cls);
        return (pm.getComponentEnabledSetting(name) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
    }

    public static boolean sendBroadCast(Context ctx, String action) {
        Intent postSetupIntent = new Intent(action);
        ctx.sendBroadcast(postSetupIntent);        
        return true;
    }

    public static void enableStrictMode() {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
        .detectAll()
        .penaltyLog()
        .penaltyDialog()
        .penaltyDropBox()
        .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
        .detectAll()
        .penaltyLog()
        .penaltyDeath()
        .penaltyDropBox()
        .build());
    }
}
